/*
 * @Author: wei_jt@ecidi.com
 * @Date: 2020-06-24 16:46:45
 * @LastEditors: wu_zh
 * @LastEditTime: 2021-10-12 14:25:15
 * @Description: file content
 */
import store from "@/store"
import * as types from '@/store/State/stateTypes'

export function getCurrentUser() {
  const userInfo = store.state[types.USER]
  return userInfo
}
export function isCustomFlow(data, prefix) {
  let flag = false
  if (data) {
    //判断是否以存在自由流程prefix
    if (data.match(new RegExp(`^${prefix}.*$`))) {
      flag = true
    }
  }
  return flag
}
// 对象数组去重(去除重复的相同value)
export function unique(arr) {
  for (var i = 0; i < arr.length; i++) {
    for (var j = i + 1; j < arr.length; j++) {
      if (JSON.stringify(arr[i]) == JSON.stringify(arr[j])) {         //第一个等同于第二个，splice方法删除第二个
        arr.splice(j, 1);
        j--;
      }
    }
  }
  return arr
}
// 下拉关联数据格式转化
export function transfer(tagAttribute, value) {
  let data = value
  if(!data){
    return  ""
  }
  if (tagAttribute === "cascader") {
    return JSON.parse(data).join("/")
  } else if (tagAttribute === "date-range" || tagAttribute === "time-range") {
    return JSON.parse(data).join("～")
  } else if (tagAttribute === "check-box") {
    return JSON.parse(data).join("，")
  }
  else if(tagAttribute === "notify"){
      // const list = ["站内信","短信","邮件"]
      let arr = JSON.parse(data)
      let list = []
      arr.forEach((item)=>{
          if(item == "0"){
            list.push("站内信")
          }else if(item == "1"){
            list.push("短信")
          }else if(item == "2"){
            list.push("邮件")
          }
      })
    return list.join(",")
  } else if (tagAttribute === "date") {
    return data.substring(0, data.length-8)
  }
  else if(tagAttribute === "org-selector"){
    return JSON.parse(data).deptName
  }else if( tagAttribute === "user-selector"){
    return JSON.parse(data).userfullname
  }
  else {
    return data
  }
}